cssvalue: Add a cssvalue for images
authorBenjamin Otte <otte@redhat.com>
Thu, 29 Mar 2012 00:58:32 +0000 (02:58 +0200)
committerBenjamin Otte <otte@redhat.com>
Tue, 17 Apr 2012 06:59:14 +0000 (08:59 +0200)
gtk/Makefile.am
gtk/gtkborderimage.c
gtk/gtkcssimagevalue.c [new file with mode: 0644]
gtk/gtkcssimagevalueprivate.h [new file with mode: 0644]
gtk/gtkcssshorthandpropertyimpl.c
gtk/gtkcssstylepropertyimpl.c
gtk/gtkcssvalue.c
gtk/gtkcssvalueprivate.h
gtk/gtkthemingbackground.c

index 1532f00ca2408bcf28a0a0aaa0b5b5a7be9031f0..f359fe4c058df4e9041c4148dc92ac41c75ca2e7 100644 (file)
@@ -431,6 +431,7 @@ gtk_private_h_sources =             \
        gtkcssimagelinearprivate.h      \
        gtkcssimageprivate.h    \
        gtkcssimageurlprivate.h \
+       gtkcssimagevalueprivate.h       \
        gtkcssimagewin32private.h       \
        gtkcssinheritvalueprivate.h     \
        gtkcssinitialvalueprivate.h     \
@@ -634,6 +635,7 @@ gtk_base_c_sources =                \
        gtkcssimagegradient.c   \
        gtkcssimagelinear.c     \
        gtkcssimageurl.c        \
+       gtkcssimagevalue.c      \
        gtkcssimagewin32.c      \
        gtkcssinheritvalue.c    \
        gtkcssinitialvalue.c    \
index a05c9d5bfe605cf09b636254e3f5670f9f999cf7..399e869c4a92d667ac6c3fa980519211a1db2f1d 100644 (file)
@@ -25,6 +25,7 @@
 #include <math.h>
 
 #include "gtkborderimageprivate.h"
+#include "gtkcssimagevalueprivate.h"
 #include "gtkstylepropertiesprivate.h"
 #include "gtkthemingengineprivate.h"
 
@@ -39,7 +40,7 @@ _gtk_border_image_init (GtkBorderImage   *image,
 {
   GtkBorder *width;
 
-  image->source = _gtk_css_value_get_object (_gtk_theming_engine_peek_property (engine, "border-image-source"));
+  image->source = _gtk_css_image_value_get_image (_gtk_theming_engine_peek_property (engine, "border-image-source"));
   if (image->source == NULL)
     return FALSE;
 
diff --git a/gtk/gtkcssimagevalue.c b/gtk/gtkcssimagevalue.c
new file mode 100644 (file)
index 0000000..f9028ae
--- /dev/null
@@ -0,0 +1,81 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 2011 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include "gtkcssimagevalueprivate.h"
+
+#include "gtkstylepropertyprivate.h"
+
+struct _GtkCssValue {
+  GTK_CSS_VALUE_BASE
+  GtkCssImage *image;
+};
+
+static void
+gtk_css_value_image_free (GtkCssValue *value)
+{
+  g_object_unref (value->image);
+  g_slice_free (GtkCssValue, value);
+}
+
+static gboolean
+gtk_css_value_image_equal (const GtkCssValue *value1,
+                           const GtkCssValue *value2)
+{
+  return value1->image == value2->image;
+}
+
+static void
+gtk_css_value_image_print (const GtkCssValue *value,
+                           GString           *string)
+{
+  if (value->image)
+    _gtk_css_image_print (value->image, string);
+  else
+    g_string_append (string, "none");
+}
+
+static const GtkCssValueClass GTK_CSS_VALUE_IMAGE = {
+  gtk_css_value_image_free,
+  gtk_css_value_image_equal,
+  gtk_css_value_image_print
+};
+
+GtkCssValue *
+_gtk_css_image_value_new (GtkCssImage *image)
+{
+  static GtkCssValue none_singleton = { &GTK_CSS_VALUE_IMAGE, 1, NULL };
+  GtkCssValue *value;
+
+  if (image == NULL)
+    return _gtk_css_value_ref (&none_singleton);
+
+  value = _gtk_css_value_new (GtkCssValue, &GTK_CSS_VALUE_IMAGE);
+  value->image = image;
+
+  return value;
+}
+
+GtkCssImage *
+_gtk_css_image_value_get_image (const GtkCssValue *value)
+{
+  g_return_val_if_fail (value->class == &GTK_CSS_VALUE_IMAGE, NULL);
+
+  return value->image;
+}
+
diff --git a/gtk/gtkcssimagevalueprivate.h b/gtk/gtkcssimagevalueprivate.h
new file mode 100644 (file)
index 0000000..2e34850
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright © 2012 Red Hat Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Alexander Larsson <alexl@gnome.org>
+ */
+
+#ifndef __GTK_CSS_IMAGE_VALUE_PRIVATE_H__
+#define __GTK_CSS_IMAGE_VALUE_PRIVATE_H__
+
+#include "gtkcssimageprivate.h"
+#include "gtkcssvalueprivate.h"
+
+G_BEGIN_DECLS
+
+GtkCssValue *   _gtk_css_image_value_new           (GtkCssImage         *image);
+
+GtkCssImage *   _gtk_css_image_value_get_image     (const GtkCssValue   *image);
+
+
+G_END_DECLS
+
+#endif /* __GTK_CSS_IMAGE_VALUE_PRIVATE_H__ */
index e4d98a091f3f21e4ac3c549595c69b5afea0491b..fe6707083bfee018ba0cfdf94edaeda53929342d 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "gtkcssenumvalueprivate.h"
 #include "gtkcssimageprivate.h"
+#include "gtkcssimagevalueprivate.h"
 #include "gtkcssnumbervalueprivate.h"
 #include "gtkcssstylefuncsprivate.h"
 #include "gtkcsstypesprivate.h"
@@ -275,7 +276,7 @@ parse_border_image (GtkCssShorthandProperty  *shorthand,
       if (!image)
         return FALSE;
     }
-  values[0] = _gtk_css_value_new_take_image (image);
+  values[0] = _gtk_css_image_value_new (image);
 
   if (value_is_done_parsing (parser))
     return TRUE;
@@ -484,7 +485,7 @@ parse_background (GtkCssShorthandProperty  *shorthand,
                 return FALSE;
             }
 
-          values[0] = _gtk_css_value_new_take_image (image);
+          values[0] = _gtk_css_image_value_new (image);
         }
       else if (values[1] == NULL &&
                _gtk_css_parser_try_enum (parser, GTK_TYPE_CSS_BACKGROUND_REPEAT, &enum_value))
index b055ed1a013dcfea6a878387c23133eb87ad6ec3..a2e35b1175e3e8475e29f30b802185b0efdf4ee3 100644 (file)
@@ -42,7 +42,7 @@
 #include "gtkbindings.h"
 #include "gtkcssimagegradientprivate.h"
 #include "gtkcssimageprivate.h"
-#include "gtkcssimageprivate.h"
+#include "gtkcssimagevalueprivate.h"
 #include "gtkcssenumvalueprivate.h"
 #include "gtkcssnumbervalueprivate.h"
 #include "gtkcssrgbavalueprivate.h"
@@ -563,20 +563,7 @@ css_image_value_parse (GtkCssStyleProperty *property,
         return FALSE;
     }
 
-  return _gtk_css_value_new_take_image (image);
-}
-
-static void
-css_image_value_print (GtkCssStyleProperty *property,
-                       const GtkCssValue   *value,
-                       GString             *string)
-{
-  GtkCssImage *image = _gtk_css_value_get_image (value);
-
-  if (image)
-    _gtk_css_image_print (image, string);
-  else
-    g_string_append (string, "none");
+  return _gtk_css_image_value_new (image);
 }
 
 static GtkCssValue *
@@ -586,7 +573,7 @@ css_image_value_compute (GtkCssStyleProperty    *property,
 {
   GtkCssImage *image, *computed;
   
-  image = _gtk_css_value_get_image (specified);
+  image = _gtk_css_image_value_get_image (specified);
 
   if (image == NULL)
     return _gtk_css_value_ref (specified);
@@ -599,7 +586,7 @@ css_image_value_compute (GtkCssStyleProperty    *property,
       return _gtk_css_value_ref (specified);
     }
 
-  return _gtk_css_value_new_take_image (computed);
+  return _gtk_css_image_value_new (computed);
 }
 
 static void
@@ -607,7 +594,7 @@ css_image_value_query (GtkCssStyleProperty *property,
                        const GtkCssValue   *css_value,
                        GValue              *value)
 {
-  GtkCssImage *image = _gtk_css_value_get_image (css_value);
+  GtkCssImage *image = _gtk_css_image_value_get_image (css_value);
   cairo_pattern_t *pattern;
   cairo_surface_t *surface;
   cairo_matrix_t matrix;
@@ -636,7 +623,7 @@ css_image_value_assign (GtkCssStyleProperty *property,
                         const GValue        *value)
 {
   g_warning ("FIXME: assigning images is not implemented");
-  return _gtk_css_value_new_take_image (NULL);
+  return _gtk_css_image_value_new (NULL);
 }
 
 static GtkCssValue *
@@ -1673,23 +1660,23 @@ _gtk_css_style_property_init_properties (void)
                                           CAIRO_GOBJECT_TYPE_PATTERN,
                                           0,
                                           css_image_value_parse,
-                                          css_image_value_print,
+                                          NULL,
                                           css_image_value_compute,
                                           css_image_value_query,
                                           css_image_value_assign,
                                           NULL,
-                                          _gtk_css_value_new_take_image (NULL));
+                                          _gtk_css_image_value_new (NULL));
 
   gtk_css_style_property_register        ("border-image-source",
                                           CAIRO_GOBJECT_TYPE_PATTERN,
                                           0,
                                           css_image_value_parse,
-                                          css_image_value_print,
+                                          NULL,
                                           css_image_value_compute,
                                           css_image_value_query,
                                           css_image_value_assign,
                                           NULL,
-                                          _gtk_css_value_new_take_image (NULL));
+                                          _gtk_css_image_value_new (NULL));
   gtk_css_style_property_register        ("border-image-repeat",
                                           GTK_TYPE_CSS_BORDER_IMAGE_REPEAT,
                                           0,
index 069a8a2fe226a9189c4482efb9b43768522201af..0ab7f56273c27fa3e262caa249b5a350a1b566d4 100644 (file)
@@ -269,17 +269,6 @@ _gtk_css_value_new_take_pattern (cairo_pattern_t *v)
   return value;
 }
 
-GtkCssValue *
-_gtk_css_value_new_take_image (GtkCssImage *v)
-{
-  GtkCssValue *value;
-
-  value = gtk_css_value_new (GTK_TYPE_CSS_IMAGE);
-  value->u.ptr = v;
-
-  return value;
-}
-
 GtkCssValue *
 _gtk_css_value_new_from_theming_engine (GtkThemingEngine *v)
 {
@@ -563,13 +552,6 @@ _gtk_css_value_get_strv (const GtkCssValue *value)
   return value->u.ptr;
 }
 
-GtkCssImage *
-_gtk_css_value_get_image (const GtkCssValue *value)
-{
-  g_return_val_if_fail (_gtk_css_value_holds (value, GTK_TYPE_CSS_IMAGE), NULL);
-  return value->u.ptr;
-}
-
 GtkBorderStyle
 _gtk_css_value_get_border_style (const GtkCssValue *value)
 {
index 22e885ac9fd8908c404cb5340bd1bc9b6a4f5c4c..4fa5589ff817a49ce05abc32cd12efb7de1c0226 100644 (file)
@@ -23,7 +23,6 @@
 #include <glib-object.h>
 #include "gtkcsstypesprivate.h"
 #include "gtksymboliccolor.h"
-#include "gtkcssimageprivate.h"
 #include "gtkthemingengine.h"
 
 G_BEGIN_DECLS
@@ -84,7 +83,6 @@ GtkCssValue *_gtk_css_value_new_from_boxed            (GType
 GtkCssValue *_gtk_css_value_new_from_color            (const GdkColor             *v);
 GtkCssValue *_gtk_css_value_new_take_symbolic_color   (GtkSymbolicColor           *v);
 GtkCssValue *_gtk_css_value_new_take_pattern          (cairo_pattern_t            *v);
-GtkCssValue *_gtk_css_value_new_take_image            (GtkCssImage                *v);
 GtkCssValue *_gtk_css_value_new_from_theming_engine   (GtkThemingEngine           *v);
 GtkCssValue *_gtk_css_value_new_take_binding_sets     (GPtrArray                  *array);
 GtkCssValue *_gtk_css_value_new_from_background_size  (const GtkCssBackgroundSize *v);
@@ -103,7 +101,6 @@ gpointer                        _gtk_css_value_get_object                 (const
 gpointer                        _gtk_css_value_get_boxed                  (const GtkCssValue *value);
 const char **                   _gtk_css_value_get_strv                   (const GtkCssValue *value);
 GtkSymbolicColor               *_gtk_css_value_get_symbolic_color         (const GtkCssValue *value);
-GtkCssImage                    *_gtk_css_value_get_image                  (const GtkCssValue *value);
 const GtkCssBackgroundSize     *_gtk_css_value_get_background_size        (const GtkCssValue *value);
 const GtkCssBackgroundPosition *_gtk_css_value_get_background_position    (const GtkCssValue *value);
 const GtkCssBorderCornerRadius *_gtk_css_value_get_border_corner_radius   (const GtkCssValue *value);
index 4fee2eea1273f95e40c941bd6fccc668f8ed94d7..63050fa8c42e981bb57653e0a3d6d6bb75b4048c 100644 (file)
 
 #include "config.h"
 
-#include "gtkcsstypesprivate.h"
 #include "gtkthemingbackgroundprivate.h"
+
+#include "gtkcssimagevalueprivate.h"
+#include "gtkcsstypesprivate.h"
 #include "gtkthemingengineprivate.h"
 
 #include <math.h>
@@ -335,7 +337,7 @@ _gtk_theming_background_init_context (GtkThemingBackground *bg)
   _gtk_theming_background_apply_clip (bg);
   _gtk_theming_background_apply_origin (bg);
 
-  bg->image = _gtk_css_value_get_image (_gtk_style_context_peek_property (bg->context, "background-image"));
+  bg->image = _gtk_css_image_value_get_image (_gtk_style_context_peek_property (bg->context, "background-image"));
 }
 
 void